package com.anjie.powerproject.repository;

import com.anjie.powerproject.entity.DataDay;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.math.BigDecimal;
import java.util.List;

public interface DataDayRepository extends JpaRepository<DataDay, Integer> {
    @Query(nativeQuery = true, value = "select * from data_day where dev_code = :code and `sdate` >= :start and `sdate` <= :end")
    List<DataDay> getDataDayList(@Param("code") String deviceCode, @Param("start") String startTime, @Param("end") String endTime);

    /**
     * 根据设备ID和时间读取点位的预测数据,时间升序排列
     */
    @Query(nativeQuery = true, value = "SELECT data FROM data_day WHERE dev_code=?1 and sdate between ?2 and ?3 ORDER BY sdate ASC")
    List<BigDecimal> getDataDayValues(String deviceCode, String startTime, String endTime);

    /**
     * 根据设备ID和时间读取点位的预测数据
     */
    @Query(nativeQuery = true, value = "SELECT data FROM data_day WHERE dev_code=?1 and sdate=?2")
    BigDecimal getDataDayValue(String deviceCode,String time);
}
